<?php
include_once('config/conn.php');
if ($_POST) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    // 判断接收数据是否为空
    if (empty($username)) {
        ShowMsg('用户不能为空');
    }

    if (empty($password)) {
        ShowMsg('密码不能为空');
    }

    $findSql = "SELECT * FROM `user` WHERE `username` = '$username' and `password` = '$password'";

    $Admin = find($findSql);

    if (!$Admin) {
        ShowMsg('用户或密码错误');
    }

    // 封装用户信息
    $data = [
        'id' => $Admin['id'],
        'username' => $Admin['username'],
    ];

    // setcookie('LoginAdmin', json_encode($data));
    $_SESSION['LoginAdmin'] = $data;
    ShowMsg('登录成功', 'index.php');
}

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <?php include_once('basic/meta.php') ?>
    <style>
        .card {
            position: absolute;
            width: 490px;
            height: 280px;
            left: 550px;
            top: 150px;
        }

        .card-header-title {
            font-size: 14px;
            font-family: 华文仿宋;
        }

        .btn-primary {
            width: 440px;
            margin-left: -105px;
            height: 40px;
            margin-top: 10px;
        }

        .is-primary {
            height: 45px;
        }

        .nav-link {
            line-height: 40px;
            margin-right: 20px;
            font-size: 14px;
            font-family: 华文中宋;
        }
    </style>
</head>

<body>
    <div class="background"></div>
    <div class="card">
        <form action="" method="post">
            <header class="card-header">
                <p class="card-header-title">学生管理系统登录入口</p>
                <a class="nav-link active" aria-current="page" href="#">没有账号？去注册</a>
            </header>
            <div class="card-content">
                <input
                    class="input is-primary"
                    type="text"
                    name="username"
                placeholder=" Username input" />

                <input
                    class="input is-primary"
                    type="password"
                    name="password"
                    style="margin-top: 20px;"
                    placeholder="Password input" />
            </div>
            <footer class="card-footer">
                <div class="d-grid gap-2 col-6 mx-auto">
                    <button class="btn btn-primary" type="submit">Login</button>
                </div>
            </footer>
        </form>

    </div>
</body>

</html>